home *** CD-ROM | disk | FTP | other *** search
- /*
- * This is the file exc.c
- * It contains the actual code required by the exception handler.
- */
- #if !defined(LINT_ARGS)
- #define LINT_ARGS
- #endif
- #include <stdio.h>
- #include <signal.h>
- #include <process.h>
- #include "exc.h"
- /*#include "cortns.h"*/
-
- #define TRUE 1
- #define FALSE 0
-
- struct ExcContext *ExcList = NULL;
- #if 0
- static char *dummy; /* Because CHANGECO will save and restore 2 words for ExcList */
- struct CoRoutine _CoMain = {0, 0, 0, 0, 0};
- extern DWORD _CoCurrent;
- DWORD CoContC = (DWORD) &_CoMain;
- #endif
-
- int exc_trace;
- int ExcNotInitialised = TRUE;
-
- /* Declare exceptions that this package may signal */
- exception CONTROL_C = "***Break";
- exception OP_FAILED = "General failure";
- exception OUT_OF_MEMORY = "Out of memory";
-
- static void exc_panic(char *, char *);
-
- static int Xcont_C()
- {
- #if 0
- if (_CoCurrent == CoContC)
- {
- signal(SIGINT, SIG_IGN);
- if (exc_trace) fprintf(stderr, "Caught signal SIGINT\n");
- (void) flushall();
- setbuf(stdin, NULL); /* Otherwise things go funny */
- signal(SIGINT, Xcont_C);
- exc_raise(CONTROL_C);
- }
- else if (CoContC != (DWORD) NULL)
- {
- ((LPCO) CoContC) -> excpend = CONTROL_C;
- }
- #endif
- signal(SIGINT, Xcont_C);
- return 0;
- };
-
- /*
- * Unfortunately, on PC-DOS this is the only signal that exists
- */
-
- static void exc_init()
- {
- if (exc_trace) fprintf(stderr, "exc_init()\n");
- ExcNotInitialised = FALSE;
- signal(SIGINT, Xcont_C);
- /* Any other signals set up here */
- /* matherr ??? */
- }
-
- /***************************************************************************
- * This routine is called at every BEGIN statement. An exception could be *
- * substituted for the panic but since a jump out of a context is the most *
- * usual cause, the saved contexts are garbage in this case. *
- ***************************************************************************/
- void exc_begin(ExcMostRecent)
- struct ExcContext *ExcMostRecent;
- {
- if (ExcNotInitialised) exc_init();
-
- ExcMostRecent->link = ExcList;
- ExcList = ExcMostRecent;
- if (exc_trace)
- fprintf(stderr, "BEGIN handling context %d\n", ExcList);
- };
-
- /***************************************************************************
- * This is called whenever a context is left normally. *
- ***************************************************************************/
- void exc_1leave()
- {
- if (exc_trace)
- fprintf(stderr, "END exception context %d\n", ExcList);
- ExcList = ExcList->link;
- }; /* End of exc_1leave */
-
- /***************************************************************************
- * This is called whenever a context is left because an exception was *
- * raised or signalled. *
- ***************************************************************************/
- void exc_2leave()
- {
- if (exc_trace)
- fprintf(stderr, "EXCEPTION leave exception context %d\n", ExcList);
- ExcList = ExcList->link;
- }; /* End of exc_2leave */
-
- /***************************************************************************
- * Raise an exception to be handled in current exception context. *
- ***************************************************************************/
- void exc_raise(code)
- exception code;
- {
- if (exc_trace)
- fprintf(stderr, "exc_raise(%s)\n", code);
- if (ExcList == NULL)
- exc_panic("Raise %s: no context\n", (char *) code);
- longjmp(ExcList->env, (int) code);
- }; /* End of exc_raise */
-
- /***************************************************************************
- * Raise an exception to be handled in outer exception context. *
- ***************************************************************************/
- void exc_signal(code)
- exception code;
- {
- if (exc_trace)
- fprintf(stderr, "exc_signal(%s)\nDISCARD context %d\n",
- code, ExcList);
- if (ExcList == NULL || (ExcList = ExcList->link) == NULL)
- exc_panic("Signal %s: no context\n", (char *) code);
- longjmp(ExcList->env, (int) code);
- }; /* End of exc_raise */
-
- static void exc_panic(s, p1)
- char *s, *p1;
- {
- fprintf(stderr, "\nException panic - ");
- fprintf(stderr, s, p1);
- exit(99); /* I want to do a core dump here! */
- }
-
-